package com.demo2do.fms.admin.entity.search.supplier;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.demo2do.fms.entity.supplier.common.Level;
import com.demo2do.fms.entity.supplier.common.Type;

/**
 * 
 * @author Chang Liu
 * 
 */
public class SupplierProfileSearch implements QueryBuilder {

    /** 供方级别 */
    private Level level;
    
    /** 供方类型*/
    private Type type;
    
    private QueryFilter filter;
    
    private QueryOrder order;
    
    /**
     * The default constructor
     */
    public SupplierProfileSearch() {
        order = new QueryOrder().add("lastModifyTime", "DESC");
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
        
        if (filter == null || refresh) {
            
            filter = new QueryFilter().addEquals("level", level)
                                      .addEquals("type", type);
            
        }
        
        return filter;
        
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM Supplier Where disabled = false" + getPreparedFilter(false).clauseSentence() + order.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return order;
    }
    
    /**
     * @return
     */
    public QueryFilter getFilter() {
        return getPreparedFilter(false);
    }

    /**
     * @return the level
     */
    public Level getLevel() {
        return level;
    }

    /**
     * @return the type
     */
    public Type getType() {
        return type;
    }

    /**
     * @param level the level to set
     */
    public void setLevel(Level level) {
        this.level = level;
    }

    /**
     * @param type the type to set
     */
    public void setType(Type type) {
        this.type = type;
    }
    
    

}
